﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Tracker.Domain.Entities;
using Tracker.Domain.DTOs;
using Tracker.Services.Abstract;
using System.ServiceModel.Activation;

namespace Tracker.WCF
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TrackerService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select TrackerService.svc or TrackerService.svc.cs at the Solution Explorer and start debugging.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class TrackerService : ITrackerService
    {
        private readonly IPositionService _positionService;
        private readonly IUserService _userService;

        public TrackerService(IPositionService positionService,
                              IUserService userService)
        {
            _positionService = positionService;
            _userService = userService;
        }

        public UserDTO Register(UserDTO dto)
        {
            _userService.Add(dto);
            return dto;
        }

        public UserDTO Login(UserDTO dto)
        {
            dto = _userService.Login(dto);
            return dto;
        }

        public void TrackPosition(PositionDTO dto)
        {
            _positionService.Add(dto);
        }

        public List<PositionDTO> GetPositions(int userID)
        {
            return _positionService.GetAll(x => x.User.ID == userID).ToList();
        }
    }
}
